<template>
  <a-card :bordered="false">
    <a-drawer title="字典列表" :width="screenWidth" @close="onClose" :visible="visible">
      <div
        :style="{
          padding: '10px',
          border: '1px solid #e9e9e9',
          background: '#fff',
        }"
      >
        <!-- 查询区域 -->
        <div class="table-page-search-wrapper">
          <a-form layout="inline" :form="form" @keyup.enter.native="searchQuery" v-show="false">
            <a-row :gutter="24">
              <a-col :xl="6" :lg="7" :md="8" :sm="24">
                <a-form-item label="规则ID" v-show="false">
                  <a-input placeholder="请输入规则ID" v-model="form.ruleId"></a-input>
                </a-form-item>
              </a-col>
              <a-col :xl="6" :lg="7" :md="8" :sm="24">
                <span style="float: left; overflow: hidden" class="table-page-search-submitButtons">
                  <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
                  <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
                  <a @click="handleToggleSearch" style="margin-left: 8px">
                    {{ toggleSearchStatus ? '收起' : '展开' }}
                    <a-icon :type="toggleSearchStatus ? 'up' : 'down'" />
                  </a>
                </span>
              </a-col>
            </a-row>
          </a-form>
        </div>
        <!-- 查询区域-END -->
        <!-- 操作按钮区域 -->
        <div class="table-operator">
          <a-button @click="handleAddPart" type="primary" icon="plus">新增</a-button>
        </div>
        <div>
          <!-- table区域-begin -->
          <a-table
            ref="table"
            size="middle"
            :scroll="{ x: true }"
            bordered
            rowKey="id"
            :columns="columns"
            :dataSource="dataSource"
            :pagination="ipagination"
            :loading="loading"
            :rowClassName="getRowClassname"
            @change="handleTableChange"
          >
            <span slot="action" slot-scope="text, record">
              <a @click="handleEdit(record)">编辑</a>
              <a-divider type="vertical" />
              <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">
                <a>删除</a>
              </a-popconfirm>
            </span>
          </a-table>
        </div>
      </div>
    </a-drawer>
    <auto-code-part-modal ref="modalForm" @ok="modalFormOk"></auto-code-part-modal>
  </a-card>
</template>

<script>
import '@/assets/less/TableExpand.less'
import pick from 'lodash.pick'
  import {filterObj} from '@/utils/util';
import { mixinDevice } from '@/utils/mixin'
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import AutoCodePartModal from './modules/AutoCodePartModal'
import { filterMultiDictText } from '@/components/dict/JDictSelectUtil'

export default {
  name: 'AutoCodePartList',
  mixins: [JeecgListMixin, mixinDevice],
  components: {
    AutoCodePartModal,
  },
  data() {
    return {
      description: '规则组成管理页面',
      // 表头
      columns: [
        {
          title: '#',
          dataIndex: '',
          key: 'rowIndex',
          width: 60,
          align: 'center',
          customRender: function (t, r, index) {
            return parseInt(index) + 1
          },
        },
        {
          title: '分段序号',
          align: 'center',
          dataIndex: 'partIndex',
        },
        {
          title: '分段类型',
          align: 'center',
          dataIndex: 'partType_dictText',
        },
        {
          title: '分段长度',
          align: 'center',
          dataIndex: 'partLength',
        },
        {
          title: '备注',
          align: 'center',
          dataIndex: 'remark',
        },
        {
          title: '操作',
          dataIndex: 'action',
          align: 'center',
          fixed: 'right',
          width: 147,
          scopedSlots: { customRender: 'action' },
        },
      ],
      url: {
        list: '/system/autoCodePart/list',
        delete: '/system/autoCodePart/delete',
        deleteBatch: '/system/autoCodePart/deleteBatch',
        exportXlsUrl: '/system/autoCodePart/exportXls',
        importExcelUrl: 'system/autoCodePart/importExcel',
      },
      dictOptions: {},
      superFieldList: [],
      visible:false,
      model: {},
      screenWidth:600,
      form: this.$form.createForm(this),
      ruleId: '',
      queryParam: {
        ruleId: undefined,
        partId: undefined,
        partCode: undefined,
        partName: '',
        partIndex: undefined,
        partType: undefined,
      },
    }
  },
  created() {
    this.getSuperFieldList()
  },
  computed: {
    importExcelUrl: function () {
      return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`
    },
  },
  methods: {
    handleAddPart() {
      let record={ruleId:this.ruleId,partId:undefined};
        this.$refs.modalForm.edit(record);
        this.$refs.modalForm.title = "新增";
      },
    add(ruleId) {
      this.ruleId = ruleId;
      this.edit({})
    },
    edit(record) {
      if (record.id) {
        this.ruleId = record.id
      }
      this.queryParam = {}
      this.form.resetFields()
      this.model = Object.assign({}, record)
      this.model.ruleId = this.ruleId
      this.visible = true;
      // 当其它模块调用该模块时,调用此方法加载字典数据
      this.loadData()
    },

    getQueryParams() {
      this.ipagination.total = 0
      var param = Object.assign({}, this.queryParam)
      param.ruleId = this.ruleId
      param.field = this.getQueryField()
      param.pageNo = this.ipagination.current
      param.pageSize = this.ipagination.pageSize
      if (this.superQueryParams) {
        param['superQueryParams'] = encodeURI(this.superQueryParams)
        param['superQueryMatchType'] = this.superQueryMatchType
      }
      return filterObj(param)
    },
    onClose() {
      this.visible = false
      this.form.resetFields()
      this.dataSource = []
    },
    showDrawer() {
      this.visible = true
    },
    onClose() {
      this.visible = false
      this.form.resetFields()
      this.dataSource = []
    },
    // 抽屉的宽度随着屏幕大小来改变
    resetScreenSize() {
      let screenWidth = document.body.clientWidth
      console.log(screenWidth);
      if (screenWidth < 600) {
        this.screenWidth = screenWidth
      } else {
        this.screenWidth = 600
      }
    },
    //增加样式方法返回值
    getRowClassname(record) {
      return 'j-table-force-nowrap1'
    },
    initDictConfig() {},
    getSuperFieldList() {
      let fieldList = []
      fieldList.push({ type: 'int', value: 'ruleId', text: '规则ID', dictCode: '' })
      fieldList.push({ type: 'int', value: 'partIndex', text: '分段序号', dictCode: '' })
      fieldList.push({ type: 'string', value: 'partType', text: '分段类型', dictCode: 'auto_code_part_type' })
      fieldList.push({ type: 'string', value: 'partCode', text: '分段编号', dictCode: '' })
      fieldList.push({ type: 'string', value: 'partName', text: '分段名称', dictCode: '' })
      fieldList.push({ type: 'int', value: 'partLength', text: '分段长度', dictCode: '' })
      fieldList.push({ type: 'string', value: 'dateFormat', text: 'dateFormat', dictCode: '' })
      fieldList.push({ type: 'string', value: 'inputCharacter', text: '输入字符', dictCode: '' })
      fieldList.push({ type: 'string', value: 'fixCharacter', text: '固定字符', dictCode: '' })
      fieldList.push({ type: 'int', value: 'seriaStartNo', text: '流水号起始值', dictCode: '' })
      fieldList.push({ type: 'int', value: 'seriaStep', text: '流水号步长', dictCode: '' })
      fieldList.push({ type: 'int', value: 'seriaNowNo', text: '流水号当前值', dictCode: '' })
      fieldList.push({ type: 'string', value: 'cycleFlag', text: '流水号是否循环', dictCode: '' })
      fieldList.push({ type: 'string', value: 'cycleMethod', text: '循环方式', dictCode: 'auto_code_cycle_method' })
      fieldList.push({ type: 'string', value: 'remark', text: '备注', dictCode: '' })
      this.superFieldList = fieldList
    },
  },
}
</script>
<style scoped>
@import '~@assets/less/common.less';
</style>
